home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0799 / 720 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  3.4 KB

  1. From: Torsten Scherer <itschere@techfak.uni-bielefeld.de>
  2. Subject: MiNT 1.09 security: f_delete() patch
  3. Date: Fri, 17 Dec 93 11:14:04 +0100
  4. Organization: private Atari-TT site
  5.  
  6. Hi!
  7.  
  8.  Here's a patch which makes MiNT's f_delete() respect the sticky bit according
  9. to the semantic how I understand it and hope it really is... Well, at least
  10. it's better and/or a bit more secure than it is now... :-)
  11.  
  12.  It goes like this:
  13.  
  14.  If I haven't write permission to the parent directory, I loose. Otherwise,
  15. if the sticky bit isn't set, I can delete anything regardless of its mode
  16. or if it's mine at all. If the sticky bit is set, I can only delete a file
  17. if it's mine, or if the whole directory is mine. In the last case I again can
  18. delete every file in the directory.
  19.  
  20.  Well, look at the code if you like... :-)
  21.  
  22. so long,
  23. TeSche
  24. -- 
  25. PS: If the above written looks weird, then that's probably because it _is_.
  26. WhoDunnIt: Torsten Scherer (Schiller, Tesche, ...)
  27. Where: Faculty of Technology, University of Bielefeld, Germany
  28. EMail: itschere@techfak.uni-bielefeld.de / tesche@hrz.uni-bielefeld.de
  29.  
  30. --- cut cut cut ---
  31.  
  32. --- orig/dosdir.c    Fri Nov 19 15:34:12 1993
  33. +++ my/dosdir.c    Fri Dec 17 11:02:50 1993
  34. @@ -716,36 +716,78 @@
  35.          release_cookie(&fc);
  36.          return xattr.attr;
  37.      }
  38.  }
  39.  
  40. +/* tesche: this one respects the sticky bit
  41. + */
  42. +
  43.  long ARGS_ON_STACK
  44.  f_delete(name)
  45.      const char *name;
  46.  {
  47. -    fcookie dir;
  48. -    long r;
  49. -    char temp1[PATH_MAX];
  50. +    fcookie    dir, fc;
  51. +    long    r;
  52. +    char    temp1[PATH_MAX];
  53. +    XATTR    dxattr, fxattr;
  54.  
  55.      TRACE(("Fdelete(%s)", name));
  56.  
  57. -    r = path2cookie(name, temp1, &dir);
  58. +/* first, get the directory cookie */
  59. +    if ((r = path2cookie(name, temp1, &dir))) {
  60. +        DEBUG(("Fdelete(%s): error %ld, perhaps path not found", name, r));
  61. +        return r;
  62. +    }
  63.  
  64. -    if (r) {
  65. -        DEBUG(("Fdelete: error %ld", r));
  66. +/* check for write permission on directory, sorry, can't use dir_access()
  67. + * here cause we may also need other bits of the XATTR structure
  68. + */
  69. +    if ((r = (dir.fs->getxattr)(&dir, &dxattr))) {
  70. +        DEBUG(("Fdelete(%s): can't get directory attributes", name));
  71. +        release_cookie(&dir);
  72.          return r;
  73.      }
  74.  
  75. -/* check for write permission on directory */
  76. -    r = dir_access(&dir, S_IWOTH);
  77. -    if (r) {
  78. -        DEBUG(("Fdelete(%s): write access to directory denied",name));
  79. -    } else {
  80. -/* BUG: we should check here for a read-only file */
  81. -        r = (*dir.fs->remove)(&dir,temp1);
  82. +    if (((dxattr.mode & S_IFMT) != S_IFDIR) || denyaccess(&dxattr, S_IWOTH)) {
  83. +        DEBUG(("Fdelete(%s): write access to directory denied", name));
  84. +        release_cookie(&dir);
  85. +        return EACCDN;
  86. +    }
  87. +
  88. +/* if sticky bit set and directory isn't ours, we need some more checks */
  89. +    if ((dxattr.mode & S_ISVTX) && (curproc->euid != dxattr.uid)) {
  90. +
  91. +        if ((r = relpath2cookie(&dir, temp1, 0, &fc, 0))) {
  92. +            DEBUG(("Fdelete(%s): error %ld, perhaps file not found", name, r));
  93. +            release_cookie(&dir);
  94. +            return r;
  95. +        }
  96. +
  97. +/* check ownership of the file */
  98. +        if ((r = (fc.fs->getxattr)(&fc, &fxattr))) {
  99. +            DEBUG(("Fdelete(%s): can't get file attributes", name));
  100. +            release_cookie(&fc);
  101. +            release_cookie(&dir);
  102. +            return r;
  103. +        }
  104. +
  105. +        if (curproc->euid != fxattr.uid) {
  106. +            DEBUG(("Fdelete(%s): write access to file denied", name));
  107. +            release_cookie(&fc);
  108. +            release_cookie(&dir);
  109. +            return EACCDN;
  110. +        }
  111. +
  112. +        release_cookie(&fc);
  113.      }
  114. +
  115. +/* actually delete the file */
  116. +    if ((r = (*dir.fs->remove)(&dir,temp1)))
  117. +        DEBUG(("Fdelete(%s): error %ld", name, r));
  118. +
  119.      release_cookie(&dir);
  120. +
  121.      return r;
  122.  }
  123.  
  124.  long ARGS_ON_STACK
  125.  f_rename(junk, old, new)
  126.